﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NUnitTest.UnitTest.Targets
{
    /// <summary>
    /// Emulates a database for concurancy in fixtures test
    /// </summary>
    static class DummyDatabase
    {
        private static int table = 0;

        /// <summary>
        /// Simulates the
        /// Creation of a test table in the database.
        /// </summary>
        /// <param name="tableUseId">The table use id.</param>
        public static void CreateTable(int tableUseId)
        {
            lock (typeof(DummyDatabase))
            {
                if (table != 0)
                {
                    throw new Exception("Table already exist");
                }
                table = tableUseId;
            }
        }


        /// <summary>
        /// Simmulation of use test table.
        /// </summary>
        /// <param name="tableUseId">The table use id.</param>
        public static void UseTable(int tableUseId)
        {
            lock (typeof(DummyDatabase))
            {
                if (table != tableUseId)
                {
                    throw new Exception("Table does not exist");
                }
            }
        }

        /// <summary>
        /// Simmulation of drops test table.
        /// </summary>
        /// <param name="tableUseId">The table use id.</param>
        public static void DropTable(int tableUseId)
        {
            lock (typeof(DummyDatabase))
            {
                if (table != tableUseId)
                {
                    throw new Exception("Table does not exist");
                }
                table = 0;
            }
        }
    }
}
